// -----------------------------
// Author: 		Dhaenens Gert	
// Creation: 	11/6/2014 8:39:00 PM				
// -----------------------------

#include "SquareOscillator.h"

SquareOscillator::SquareOscillator()
	: Oscillator(SoundWaveType::Square)
{
}

SquareOscillator::~SquareOscillator()
{
}

Float SquareOscillator::Sample(Float t) const
{
	// Generate the Square Wave
	Float s = 0.0f;
	for (UInt32 h = 1; h <= Harmonics; ++h)
	{
		Float fh = 2.0f * (Float)h - 1.0f;
		Float sh = (Math::Sin(Math::PiTimes2 * fh * Frequency * t));
		sh /= fh;
		s += sh;
	}
	s = (4.0f / Math::Pi) * s;

	return s;
}